package com.dq.domain.goods;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/16
 * @描述
 */
@Data
@Entity
@ApiModel(value = "商品规格")
public class Specification extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "名称")
    protected String name;
    @ApiModelProperty(value = "排序")
    protected Long sortNo;
    @ApiModelProperty("机构")
    @ManyToOne
    protected SysSection org;

    @Data
    @ApiModel(value = "规格视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        private Long id;
        @ApiModelProperty(value = "名称")
        private String name;
        @ApiModelProperty("机构名称")
        private String orgName;
        @ApiModelProperty("机构id")
        private Long orgId;
        @ApiModelProperty("创建时间")
        private String createTime;
        @ApiModelProperty("排序")
        private Long sortNo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.name = this.name;
        vo.orgName = this.org == null ? "" : this.org.getSimpleName();
        vo.orgId = this.org == null ? null : this.org.getId();
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.sortNo = fmt(this.sortNo);
        return vo;
    }
}
